spinlock: Introduce spin_lock_cb()
authorBoris Ostrovsky <boris.ostrovsky@oracle.com>
Wed, 16 Aug 2017 18:31:00 +0000 (20:31 +0200)
committerJan Beulich <jbeulich@suse.com>
Tue, 22 Aug 2017 08:40:09 +0000 (10:40 +0200)
commit462090402a1485504c18d79f7a22b8ead03f1fdd
tree5bd60813f45c2942299afc2b7fb155e70d108691
parent55066985050f5366ed800dcd5ee9308d6ff943b1
spinlock: Introduce spin_lock_cb()

While waiting for a lock we may want to periodically run some
code. This code may, for example, allow the caller to release
resources held by it that are no longer needed in the critical
section protected by the lock.

Specifically, this feature will be needed by scrubbing code where
the scrubber, while waiting for heap lock to merge back clean
pages, may be requested by page allocator (which is currently
holding the lock) to abort merging and release the buddy page head
that the allocator wants.

We could use spin_trylock() but since it doesn't take lock ticket
it may take long time until the lock is taken. Instead we add
spin_lock_cb() that allows us to grab the ticket and execute a
callback while waiting. This callback is executed on every iteration
of the spinlock waiting loop.

Since we may be sleeping in the lock until it is released we need a
mechanism that will make sure that the callback has a chance to run.
We add spin_lock_kick() that will wake up the waiter.

Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Acked-by: Julien Grall <julien.grall@arm.com>
xen/common/spinlock.c
xen/include/asm-arm/spinlock.h
xen/include/asm-x86/spinlock.h
xen/include/xen/spinlock.h